VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmUserGroup 
   BackColor       =   &H8000000D&
   Caption         =   "UserGroup"
   ClientHeight    =   3330
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7485
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   ScaleHeight     =   3330
   ScaleWidth      =   7485
   StartUpPosition =   3  'Windows Default
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   5040
      Top             =   120
      Visible         =   0   'False
      Width           =   2280
      _ExtentX        =   4022
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "1.User Group"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00E0E0E0&
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   1110
      Left            =   315
      TabIndex        =   9
      Top             =   1410
      Width           =   6720
      Begin VB.TextBox txtGroupName 
         Height          =   345
         Left            =   2565
         MultiLine       =   -1  'True
         TabIndex        =   13
         Top             =   525
         Width           =   3240
      End
      Begin VB.TextBox txtUserGroup 
         Height          =   288
         Left            =   2535
         TabIndex        =   12
         Top             =   72
         Width           =   1008
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "User Group"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   225
         Index           =   5
         Left            =   1140
         TabIndex        =   11
         Top             =   150
         Width           =   1110
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Group Name"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   225
         Index           =   3
         Left            =   1155
         TabIndex        =   10
         Top             =   570
         Width           =   1125
      End
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "&Delete"
      Height          =   372
      Left            =   4725
      TabIndex        =   6
      Top             =   2685
      Width           =   960
   End
   Begin VB.CommandButton cmdAddnew 
      Caption         =   "&New"
      Height          =   372
      Left            =   495
      TabIndex        =   4
      Top             =   2700
      Width           =   996
   End
   Begin VB.CommandButton cmdEdit 
      Caption         =   "&Edit"
      Height          =   372
      Left            =   1560
      TabIndex        =   3
      Top             =   2685
      Width           =   948
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "&Save"
      Height          =   372
      Left            =   2595
      TabIndex        =   2
      Top             =   2685
      Width           =   984
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "&Cancel"
      Height          =   372
      Left            =   3630
      TabIndex        =   1
      Top             =   2685
      Width           =   1032
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "&Exit"
      Height          =   372
      Left            =   5745
      TabIndex        =   0
      Top             =   2685
      Width           =   1080
   End
   Begin MSDataListLib.DataCombo cboUserGroup 
      Bindings        =   "frmUserGroup.frx":0000
      Height          =   288
      Left            =   3396
      TabIndex        =   7
      Top             =   1008
      Width           =   2256
      _ExtentX        =   3995
      _ExtentY        =   556
      _Version        =   393216
      ListField       =   "GroupName"
      BoundColumn     =   "UserGroup"
      Text            =   ""
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "Select User Group"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   7.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0080FFFF&
      Height          =   225
      Index           =   2
      Left            =   1755
      TabIndex        =   8
      Top             =   1035
      Width           =   1635
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "User Group"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   16.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   495
      Index           =   1
      Left            =   1935
      TabIndex        =   5
      Top             =   195
      Width           =   2625
   End
End
Attribute VB_Name = "frmUserGroup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim OldUserGroup As String
Private Sub WriteToFile()
Dim SQLInsert As String
If ISADDING Then
    SQLInsert = " INSERT INTO UserGroup " & _
                  "(UserGroup,GroupName) " & _
                "VALUES " & _
                  "('" & txtUserGroup & "', '" & txtGroupName & "')"
 Else
    SQLInsert = "UPDATE UserGroup SET UserGroup = '" & txtUserGroup & "', GroupName ='" & txtGroupName & "' " & _
                " WHERE UserGroup ='" & OldUserGroup & "'"
             
End If

Set cmdExecute = New ADODB.Command
Set cmdExecute.ActiveConnection = DBconn
cmdExecute.CommandText = SQLInsert
cmdExecute.Execute

End Sub

Private Sub WriteToScreen()
If ISADDING Then 'gan rong
        txtUserGroup = ""
        txtGroupName = ""
       ' txtUMCVF = 0
Else
        Dim TBL As ADODB.Recordset
        Set TBL = New ADODB.Recordset
        TBL.Open "  Select UserGroup.*From UserGroup where  UserGroup ='" & cboUserGroup.BoundText & "'", DBconn, adOpenKeyset, adLockOptimistic, adCmdText
        If TBL.EOF = False Then
            txtUserGroup = IIf(IsNull(TBL!UserGroup), "", TBL!UserGroup)
            txtGroupName = IIf(IsNull(TBL!GroupName), "", TBL!GroupName)
        '    txtUMCVF = IIf(IsNull(TBL!UMCVF), "", TBL!UMCVF)
        Else
            cboUserGroup.BoundText = ""
            txtUserGroup = ""
            txtGroupName = ""
         '   txtUMCVF = 0
        End If
        TBL.Close
End If
OldUserGroup = txtUserGroup
End Sub

Sub ButtonStatus()
cmdAddnew.Enabled = Not ISEDITING
cmdEdit.Enabled = Not ISEDITING
cmdSave.Enabled = ISEDITING ' And txtIMITN <> ""
cmdDelete.Enabled = Not ISEDITING 'And txtIMITN <> ""
cmdCancel.Enabled = ISEDITING
Frame1.Enabled = ISEDITING
'txtIMITN.Locked = Not ISADDING ' Lock item code tru truong hop ISADDING=true
'txtDepartment.Enabled = ISEDITING
'cboDepartment.Visible = Not ISADDING
'txtDepartmentID.Visible = ISADDING
End Sub

Private Sub cboUserGroup_Click(Area As Integer)
If Area = 2 Then
    WriteToScreen
End If
End Sub

Private Sub cmdAddnew_Click()
ISADDING = True
ISEDITING = True
WriteToScreen

' Ham Gan tri man hinh
ButtonStatus

End Sub

Private Sub cmdCancel_Click()
' Gan tri man nhinh
ISADDING = False
ISEDITING = False

ButtonStatus
txtUserGroup = cboUserGroup.BoundText
WriteToScreen

End Sub

Private Sub cmdDelete_Click()
Dim SQL As String
Response = MsgBox("If you delete this Group some Information related (User & Right  in this group) will be delete" & Chr(13) & "Do you really to delete this Group?", vbYesNo + vbCritical + vbDefaultButton2, "Chu y'")
If Response = vbYes Then
       DBconn.Execute "DELETE FROM UserGroup WHERE UserGroup = '" & cboUserGroup.BoundText & "'"
       DBconn.Execute "Update  USERS Set UserGroup='',USERName='' where UserGroup='" & cboUserGroup.BoundText & "'"
       DBconn.Execute "DELETE  from GroupFunction  where UserGroup='" & cboUserGroup.BoundText & "'"
        Adodc1.Refresh
End If
'WriteToScreen (0)

End Sub

Private Sub cmdEdit_Click()
ISEDITING = True
' Ham gan tri man hinh
ISADDING = False
ISEDITING = True
ButtonStatus

End Sub

Private Sub cmdExit_Click()
Unload frmUserGroup
End Sub

Private Sub cmdSave_Click()

WriteToFile
Adodc1.Refresh
'''''''''''
ISADDING = False
ISEDITING = False

ButtonStatus


End Sub

Private Sub Form_Load()
'BIENCHUNG
Adodc1.ConnectionString = ConnectString
Adodc1.ConnectionTimeout = 10
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "UserGroup"
Adodc1.Refresh

ISADDING = False
ISEDITING = False
ButtonStatus

End Sub


Private Sub txtGroupName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then cmdSave.SetFocus

End Sub

Private Sub txtUserGroup_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If ValidMaso(OldUserGroup, txtUserGroup, "UserGroup", " UserGroup='" & txtUserGroup & "'") Then
        MsgBox "This code is already exist"
        txtUserGroup.SetFocus
    Else
        txtGroupName.SetFocus
    End If
End If
End Sub
